# TODO: To average tiff file
# 
# Author: phamha
###############################################################################


library(raster)
library(stringr)

path= "/home/phamha/Desktop/DIS/MOD04"
listFile = list.files(path = path,pattern="10km.tif$",full.names = TRUE,recursive=TRUE)
stack_raster=stack()

for (index2 in 1:length(listFile)) {
	full_name=listFile[index2]
	stack_raster=addLayer(stack_raster,full_name)
}
	#daily_raster=count(stack_raster,na.rm=TRUE)
	daily_raster=sum(stack_raster!=-9999)
	out_file=paste(path,"/","mod_count.tif",sep="")
	writeRaster(daily_raster,filename=out_file,format="GTiff")
	
	

print("done")






